<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="shortcut icon" href="${pageContext.request.contextPath }/bootstrap/img/favicon.ico">
<link href="${pageContext.request.contextPath }/bootstrap/css/style.min.css?v=4.0.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/animate.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/bootstrap/css/jquery-confirm.css"/>
<link href="${pageContext.request.contextPath }/bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<link href="${pageContext.request.contextPath }/bootstrapStyle/js/plugins/fancybox/jquery.fancybox.css" rel="stylesheet"/>
<title>医院端管理</title>
</head>
<body>
	<div class="panel panel-default">
	    <div class="panel-body form-group" style="margin-top: 0px;">
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">所属城市：</label>
	        <div class="col-sm-2">
	            <select class="form-control" name="hospadrprovince" id="hospadrprovince1" onchange="loadcity()">
					<option value="0">---请选择省---</option>
				</select>
	        </div>
	        <div class="col-sm-2">
	            <select class="form-control" name="hospadrcity" id="hospadrcity1" onchange="loadarea()">
					<option value="0">---请选择市---</option>
				</select>
	        </div>
	        <div class="col-sm-2">
	            <select class="form-control" name="hospadrarea" id="hospadrarea1">
					<option value="0">---请选择县（区）---</option>
				</select>
	        </div>
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">医院等级：</label>
	        <div class="col-sm-2">
	            <select class="form-control" name="hosplevel" id="hosplevel1">
					<option value="">全部</option>
				</select>
	        </div>
	    </div>
	    <div class="panel-body form-group" style="margin-top: 0px;">
	    	<label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">账户审核情况：</label>
	        <div class="col-sm-2">
	            <select class="form-control" name="type" id="type">
					<option value="0">全部</option>
					<option value="1">未审核</option>
					<option value="2">等待审核</option>
					<option value="3">已审核</option>
					<option value="4">未通过审核</option>
				</select>
	        </div>
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">注册手机号：</label>
	        <div class="col-sm-2">
	            <input type="text" class="form-control" name="hosploginphone" id="hosploginphone1"/>
	        </div>
	        <label class="col-sm-1 control-label" style="text-align: right; margin-top:5px">审核提交时间：</label>
	        <div class="col-sm-3 form-group">
                <div class="input-daterange input-group" id="datepicker">
                    <input type="text" class="input-md form-control" id="startdatetime" name="startdatetime" value="" />
                    <span class="input-group-addon">到</span>
                    <input type="text" class="input-md form-control" id="enddatetime" name="enddatetime" value="" />
                </div>
            </div>
	        <div class="col-sm-1 control-label">
	            <button class="btn btn-primary" id="search_btn">查询</button>
	        </div>
	     </div>
	</div>
	<!-- 动态加载table -->
	<table id="hospitaltab" class="table table-hover"></table>
	<div class="modal inmodal fade" id="HospitalDetailsModal" tabindex="-1" role="dialog"  aria-hidden="true">
    	<div class="modal-dialog" style="width: 1200px">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">用户详情</h4>
               	</div>
                <div class="modal-body">
                	<div class="wrapper wrapper-content">
        				<div class="row animated fadeInRight">
                    		<div class="col-sm-4">
                				<div class="ibox float-e-margins">
                    				<div class="ibox-title">
				                        <h4>个人登陆资料</h4>
				                    </div>
				                    <div>
				                    	<div class="ibox-content profile-content">
			                    			<img alt="image" id="hosploginpix" style="max-width:100px" class="img-rounded" src="${pageContext.request.contextPath}/bootstrap/img/a5.jpg">
			                    		</div>
			                    		<div class="ibox-content profile-content">
			                    			<p><i class="fa fa-user"> 登陆手机号码：</i><strong><a id="hosploginphone"></a></strong></p>
				                            <hr/>
				                            <p><i class="fa fa-user"> 登陆账号审核状态：</i><strong><a id="hosplogintypename"></a></strong></p>
				                            <hr/>
				                            <p><i class="fa fa-map-marker"> 上次登陆时间：</i><strong><a id="hosplogintime"></a></strong></p>
				                            <hr/>
			                    		</div>
				                    </div>
				                </div>
				        	</div>
				        	<div class="col-sm-8">
                				<div class="ibox float-e-margins">
                    				<div class="ibox-title">
				                        <h4>个人详细信息</h4>
				                    </div>
				                    <div class="ibox-content">
			                    		<div class="row">
			                    			<div class="col-sm-6">
			                    				<p><i class="fa fa-user"> 医院名称：</i><strong><a id="hospname"></a></strong></p>
												<hr/>
						                    	<p><i class="fa fa-credit-card"> 身份证号码：</i><strong><a id="hospregidcard"></a></strong></p>
						                 		<hr/>
						                 		<p><i class="fa fa-credit-card"> 所在地址：</i><strong><a id="address1"></a></strong></p>
						                 		<hr/>
			                    			</div>
			                    			<div class="col-sm-6">
			                    				<p><i class="fa fa-user"> 联系电话：</i><strong><a id="hospphone"></a></strong></p>
						                    	<hr/>
						                    	<p><i class="fa fa-user"> 医院等级：</i><strong><a id="hosplevelname"></a></strong></p>
						                    	<hr/>
						                 		<p><i class="fa fa-credit-card"> 所在区和路：</i><strong><a id="address2"></a></strong></p>
						                 		<hr/>
			                    			</div>
			                    			<div class="col-sm-12">
			                    				<p><i class="fa fa-info"> 医院介绍：</i><strong><a id="hospabs"></a></strong></p>
		                 						<hr/>
						                 		<p><i class="fa fa-info"> 医院特色介绍：</i><strong><a id="hospfeature"></a></strong></p>
						                 		<hr/>
			                    			</div>
			                    			<!-- 显示照片 -->
			                    			<div id="photoPanel">
			                    				
			                    			</div>
			                    		</div>
				                    </div>
				                </div>
				        	</div>
        				</div>
        			</div>
                </div>
				<div class="modal-footer">
                	<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
           		</div>
           	</div>
        </div>
	</div>
	
	<div class="modal inmodal fade" id="EditModal" tabindex="-1" role="dialog"  aria-hidden="true">
    	<div class="modal-dialog modal-lg" style="width:800px;">
        	<div class="modal-content">
            	<div class="modal-header">
                	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">编辑医院信息</h4>
               	</div>
                <div class="modal-body">
                	<div class="row">
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院名称：</label>
		                        <input type="text" name="hospname" id="Ehospname" class="form-control" placeholder="医院名称">
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院联系电话：</label>
		                        <input type="text" name="hospphone" id="Ehospphone" class="form-control" placeholder="医院联系电话">
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院注册身份证：</label>
		                        <input type="text" name="hospregidcard" id="Ehospregidcard" class="form-control" placeholder="医院注册身份证号码">
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院等级：</label>
		                        <select class="form-control" name="hospgrade" id="Ehospgrade">
		                        	<option value="0">---请选择---</option>
								</select>
		                   	</div>
                		</div>
                		<div class="col-sm-12">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院详细地址：</label>
		                        <input type="text" name="hospadr" id="Ehospadr" class="form-control" placeholder="医院详细地址">
		                        <input type="hidden" id="Ehospadrprovince"/><input type="hidden" id="Ehospadrcity"/>
		                        <input type="hidden" id="Ehospadrarea"/><input type="hidden" id="Ehospadrother"/>
		                        <input type="hidden" id="Ehospadrlon" value="117.171056"/><input type="hidden" id="Ehospadrlat" value="31.833742"/>
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院简介：</label>
		                        <textarea name="hospabs" id="Ehospabs" rows="4" class="form-control" placeholder="医生简介"></textarea>
		                   	</div>
                		</div>
                		<div class="col-sm-6">
                			<div class="form-group draggable">
		                    	<label class="control-label">医院特色：</label>
		                        <textarea name="hospfeature" id="Ehospfeature" rows="4" class="form-control" placeholder="医生简介"></textarea>
		                   	</div>
                		</div>
                	</div>
                </div>
				<div class="modal-footer">
                	<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                	<button type="button" class="btn btn-primary" onclick="hospinfoSubmit();" id="hospinfoBtn">提交</button>
           		</div>
           	</div>
        </div>
	</div>
	
	<div class="modal fade" id="myMapModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" >
		<div class="modal-dialog" style="width: 1000px;height:800px;">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true"> &times;</button>
					<h4 class="modal-title" id="myModalLabel"><a>百度地图选点(鼠标滑动放大缩小地图,左击拖动移动地图。点击获取经纬度)</a></h4>
				</div>
				<div class="modal-body" id="map_main" style="height:500px;">地图容器</div>
				<div class="modal-footer">
					<input style="width:300px;float:left;" type="text" placeholder="左击地点，生成经纬度" value="" id="map_txt" class="form-control" readonly=""/>
					<!-- 经度 -->
					<input type="hidden" id="lng"/>
					<!-- 纬度 -->
					<input type="hidden" id="lat"/>
					<!-- 省 -->
					<input type="hidden" id="province"/>
					<!-- 市 -->
					<input type="hidden" id="city"/>
					<!-- 区 -->
					<input type="hidden" id="area"/>
					<!-- 街 -->
					<input type="hidden" id="other"/>
					<button type="button" class="btn btn-primary" onclick="setMapValue()" data-dismiss="modal">设置为此地址</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
	
    <script src="${pageContext.request.contextPath }/bootstrap/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/jquery-confirm.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrap/js/moment-with-locales.min.js"></script>
	<script src="${pageContext.request.contextPath }/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
	<script src="${pageContext.request.contextPath }/bootstrapStyle/js/plugins/fancybox/jquery.fancybox.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=2d12993ce41407db4050140fe342d9ba"></script>
    <script>
	  //根据窗口调整表格高度
	    $(window).resize(function() {
	        $('#hospitaltab').bootstrapTable('resetView', {
	            height: tableHeight()
	        })
	    })
	    //查询按钮事件
	    $('#search_btn').click(function(){
	        $('#hospitaltab').bootstrapTable('refresh',{url: '${pageContext.request.contextPath}/Main/Hospital/hospitalListAjax.action'});
	    })
	    //tableHeight函数
	    function tableHeight(){
	        //可以根据自己页面情况进行调整
	        return $(window).height();
	    }
	  	function refreshTab(){
	  		$('#hospitaltab').bootstrapTable('refresh');
	  	}
		//生成用户数据
	    $('#hospitaltab').bootstrapTable({
	        method: 'get',
	        contentType: "application/x-www-form-urlencoded",//必须要有！！！！
	        url:"${pageContext.request.contextPath}/Main/Hospital/hospitalListAjax.action",//要请求数据的文件路径,
	        height:tableHeight(),//高度调整
	        striped: true, //是否显示行间隔色
	        dataField: "rows",//bootstrap table 可以前端分页也可以后端分页，这里
	        //我们使用的是后端分页，后端分页时需返回含有total：总记录数,这个键值好像是固定的  
	        //rows： 记录集合 键值可以修改  dataField 自己定义成自己想要的就好
	        pageNumber: 1, //初始化加载第一页，默认第一页
	        pagination:true,//是否分页
	        queryParamsType:'limit',//查询参数组织方式
	        queryParams:function(params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的    
	            return {//这里的params是table提供的    
	                offset : params.offset,//从数据库第几条记录开始    
	                limit : params.limit,
	                type:$('#type').val(),
	                hospadrprovince:$('#hospadrprovince1').val(),
                    hospadrcity:$('#hospadrcity1').val(),
                    hospadrarea:$('#hospadrarea1').val(),
                    hosplevel:$('#hosplevel1').val(),
                    hosploginphone:$('#hosploginphone1').val(),
                    startdatetime:$('#startdatetime').val(),
	                enddatetime:$('#enddatetime').val()
	            //找多少条    
	            };},//请求服务器时所传的参数
	        sidePagination:'server',//指定服务器端分页
	        pageSize:10,//单页记录数
	        pageList:[1,5,10,30,50,100],//分页步进值
	        showRefresh:true,//刷新按钮
	        showColumns:true,
	        clickToSelect: true,//是否启用点击选中行
	        toolbarAlign:'right',//工具栏对齐方式
	        buttonsAlign:'right',//按钮对齐方式
	        toolbar:'#toolbar',//指定工作栏
	        columns:[
	            {
	                title:'全选',
	                field:'select',
	                //复选框
	                checkbox:true,
	                width:25,
	                align:'center',
	                valign:'middle'
	            },
	            {
	                title:'医院端登陆ID',
	                field:'hosploginid'
	            },
	            {
	                title:'医院名称',
	                field:'hospname'
	            },
	            {
	                title:'医院等级',
	                field:'hosplevelname'
	            },
	            {
	                title:'医院端登陆手机号',
	                field:'hosploginphone'
	            },
	            {
	                title:'医院账户状态',
	                field:'hosplogintypename'
	            },
	            {
	                title:'操作',
	                field:'hosplogintype',
	              	//列数据格式化
	                formatter:operate
	            },
	        ],
	        locale:'zh-CN',//中文支持,
	        responseHandler:function(rows){
	            //在ajax获取到数据，渲染表格之前，修改数据源
	            return rows;
	        }
	    })
	    //操作序列规则化
		function operate(value,row,index){
	    	return '<button class="btn btn-primary" style="height:30px" onclick="Details('+row.hosploginid+')">详情</button>&nbsp;&nbsp<button class="btn btn-info" style="height:30px" onclick="EditInfo('+row.hosploginid+')">编辑</button>';
		}
	    function Details(hosploginid){
			//alert(hosploginid);
			$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/Main/Hospital/getHospitalDetails.action",
				data:"hosploginid="+hosploginid,
				async: true,
	    		success:function(data){
	    			//alert("data.details.docname="+data.details.docname);
	    			if(data.code==100){
	    				$('#HospitalDetailsModal').modal('show');
	    				ModalPadding(data.details);
	    			}else{
	    				$.alert(""+data.msg);
	    			}
	    		},error:function(request){
	    			
	    		}
			})
		}
	    
	    function EditInfo(hosploginid){
	    	//alert(hosploginid);
	    	$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/Main/Hospital/getHospitalDetails.action",
				data:"hosploginid="+hosploginid,
				async: true,
	    		success:function(data){
	    			//alert("data.details.docname="+data.details.docname);
	    			if(data.code==100){
	    				var details=data.details;
	    				$("#EditModal").modal('show');
	    				$("#Ehospname").val(details.hospname);//
	    				$("#Ehospregidcard").val(details.hospregidcard);//
	    				$("#Ehospphone").val(details.hospphone);//
	    				$("#Ehospgrade").val(details.hosplevelname);//
	    				$("#Ehospabs").val(details.hospabs);//
	    				$("#Ehospfeature").val(details.hospfeature);//
	    				$("#Ehospadr").val(details.hospadrprovince+":"+details.hospadrcity+":"+details.hospadrarea+":"+details.hospadrother);//+":"+details.hospadrlon+":"+details.hospadrlat
	    				$("#Ehospadrprovince").val(details.hospadrprovince);
	    				$("#Ehospadrcity").val(details.hospadrcity);
	    				$("#Ehospadrarea").val(details.hospadrarea);
	    				$("#Ehospadrother").val(details.hospadrother);
	    			}else{
	    				$.alert(""+data.msg);
	    			}
	    		},error:function(request){
	    			$.alert("医院信息加载失败");
	    		}
			})
	    }
	    
	    function hospinfoSubmit(){
	    	var hospname = $("#Ehospname").val();//
			var hospregidcard = $("#Ehospregidcard").val();//
			var hospphone = $("#Ehospphone").val();//
			var hosplevelname = $("#Ehospgrade").val();//
			var hospabs = $("#Ehospabs").val();//
			var hospfeature = $("#Ehospfeature").val();//
			var hospadrprovince = $("#Ehospadrprovince").val();
			var hospadrcity = $("#Ehospadrcity").val();
			var hospadrarea = $("#Ehospadrarea").val();
			var hospadrother = $("#Ehospadrother").val();
			
			var param="hospname="+hospname+"&hospregidcard="+hospregidcard+"&hospphone="+hospphone+
			"&hosplevelname="+hosplevelname+"&hospabs="+hospabs+"&hospfeature="+hospfeature+
			"&hospadrprovince="+hospadrprovince+"&hospadrcity="+hospadrcity+"&hospadrarea="+hospadrarea+"&hospadrother="+hospadrother;
			
			$.confirm({
	    		title: '提示!',
    		    content: '您确定要提交保存？',
    		    type: 'blue',
    		    typeAnimated: true,
    		    buttons: {
    		    	确定: function () {
    		    		$("#hospinfoBtn").html('<i class="fa fa-spinner fa-spin"></i>处理中...');
    		    		$("#hospinfoBtn").prop('disabled',true);
    		    		$.ajax({
    		    			type:"post",
    		    			url:"${pageContext.request.contextPath}/Main/Hospital/hospitalinfoSubmit.action",
    		    			data:param,
    		    			async: true,
    		    			success:function(data){
    		    				$("#hospinfoBtn").html('提交');
    	    		    		$("#hospinfoBtn").prop('disabled',false);
    		        			$.alert(data.msg);
    		    				if(data.code==100){
    		    					$('#EditModal').modal('hide');
    		        				refreshTab();
    		    				}
    		    			},error:function(request){
    		    				$("#hospinfoBtn").html('提交');
    	    		    		$("#hospinfoBtn").prop('disabled',false);
    		        			$.alert("向服务器请求失败！");
    		    			}
    		    		});
    		    	},
    		    	取消:function(){},
    		    }
	    	})
	    }
	    
	    function ModalPadding(data){
	    	$("#hosploginpix").attr('src',data.hosploginpix);//登陆头像
			$("#hosploginphone").html(data.docloginphone);//登录手机号码
			$("#hosplogintypename").html(data.doclogintypename);//账号登陆状态字
			$("#hosplogintime").html(data.doclogintime);//上次登陆时间
			
			$("#hospname").html(data.hospname);//医院名称
			$("#hospregidcard").html(data.hospregidcard);//
			$("#hospphone").html(data.hospphone);//
			$("#hosplevelname").html(data.hosplevelname);//
			$("#address1").html(data.hospadrprovince+","+data.hospadrcity);//所在地址
			$("#address2").html(data.hospadrarea+","+data.hospadrother);//所在地址
			$("#hospabs").html(data.hospabs);
			$("#hospfeature").html(data.hospfeature);
			for(var i=0;i<data.hosppraclicense.length;i++){
				var hosppraclicense=data.hosppraclicense[i];
				var photoname="注册医院执业许可证照片*"+Number(i+1);
				if(hosppraclicense!=""){
					AddPhotoPanel(hosppraclicense,photoname);
				}
			}
			for(var i=0;i<data.hospregdocquacer.length;i++){
				var hospregdocquacer=data.hospregdocquacer[i];
				var photoname="注册人医师资格证照片*"+Number(i+1);
				if(hospregdocquacer!=""){
					AddPhotoPanel(hospregdocquacer,photoname);
				}
			}
			for(var i=0;i<data.hosplegalcer.length;i++){
				var hosplegalcer=data.hosplegalcer[i];
				var photoname="医院法人证明照片*"+Number(i+1);
				if(hosplegalcer!=""){
					AddPhotoPanel(hosplegalcer,photoname);
				}
			}
			for(var i=0;i<data.hosporgcodecer.length;i++){
				var hosporgcodecer=data.hosporgcodecer[i];
				var photoname="质监部门机构代码证*"+Number(i+1);
				if(hosporgcodecer!=""){
					AddPhotoPanel(hosporgcodecer,photoname);
				}
			}
	    }
	    function AddPhotoPanel(data,photoname){
	    	$("#photoPanel").append('<div class="col-sm-6">'+
			    	'<div class="panel panel-default">'+
			    	'<div class="panel-heading">'+
		            	'<h5 class="panel-title">'+
		                	'<a data-toggle="collapse" data-parent="#accordion" href="javscript:;">'+photoname+'</a>'+
		            	'</h5>'+
		            '</div>'+
		     		'<div id="" class="panel-collapse collapse in">'+
	                	'<div class="panel-body">'+
	                       	'<a class="fancybox" target="_blank" href="'+data+'" title="'+photoname+'">'+
					        	'<img alt="image" src="'+data+'" style="width:320px;height:180px;"/>'+
						    '</a> '+
	            		'</div>'+
	            	'</div>'+
	           ' </div>'+
	    	'</div>');
	    }
	</script>
	<script type="text/javascript">
		$(function () {
			$('#startdatetime').datetimepicker({  
				format: 'YYYY-MM-DD',  
				locale: moment.locale('zh-cn')  
			});
			$('#enddatetime').datetimepicker({  
				format: 'YYYY-MM-DD',  
				locale: moment.locale('zh-cn')  
			});
			$.ajax({
    			type:"post",
    			url:"${pageContext.request.contextPath}/Main/Patient/loadcity.action",
    			async: true,
    			data:"cityparentcode=0",
        		success:function(data){
        			//alert("data.details.docname="+data.details.docname);
        			if(data.code==100){
        				var datalist = data.list;
                        for (var i = 0; i < datalist.length; i++) {  
                            $('#hospadrprovince1').append("<option value='" + datalist[i].citycode + "' >" + datalist[i].cityname + "</option>");  
                        }
        			}else{
        				$.alert(data.msg);
        			}
        		},error:function(){
        			$.alert("加载省失败!!!");
        		}
    		})
    		$.ajax({
    			type:"post",
    			url:"${pageContext.request.contextPath}/Main/Doctor/loadhosplevel.action",
    			async: true,
        		success:function(data){
        			//alert("data.details.docname="+data.details.docname);
        			if(data.code==100){
        				var datalist = data.list;
                        for (var i = 0; i < datalist.length; i++) {  
                            $('#hosplevel1').append("<option value='" + datalist[i].hosplevelname + "' >" + datalist[i].hosplevelname + "</option>");  
                            $('#Ehospgrade').append("<option value='" + datalist[i].hosplevelname + "' >" + datalist[i].hosplevelname + "</option>");  
                        }
        			}else{
        				$.alert(data.msg);
        			}
        		},error:function(){
        			$.alert("加载所属医院级别失败!!!");
        		}
    		})
		});
		function loadcity(){
			var cityparentcode = $("#hospadrprovince1").val();
			if(cityparentcode==0){
				$("#hospadrcity1").empty();  
                $("#hospadrarea1").empty();
                $('#hospadrcity1').append("<option value='0' selected='selected' >" + '---请选择市---' + "</option>");  
                $('#hospadrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
			}else{
				$("#hospadrcity1").empty();  
                $("#hospadrarea1").empty();
                $.ajax({  //页面首加载省下拉框数据
                    type: "post",  
                    url: "${pageContext.request.contextPath}/Main/Patient/loadcity.action",
            		async: true,
                    data:"cityparentcode="+cityparentcode,
                    success: function (data) {
                    	var datalist = data.list;
                    	$('#hospadrcity1').append("<option value='0' selected='selected' >" + '---请选择市---' + "</option>");  
                        $('#hospadrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
                        for (var i = 0; i < datalist.length; i++) {
                            $('#hospadrcity1').append("<option value='" + datalist[i].citycode + "' >" + datalist[i].cityname + "</option>");  
                        }  
                    },  
                    error: function () {  
                        $.alert("加载市失败!!!");  
                    }  
                });
			}
		}
		function loadarea(){
			var cityparentcode = $("#hospadrcity1").val();
			if(cityparentcode==0){
                $("#hospadrarea1").empty();
                $('#hospadrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
			}else{
                $("#hospadrarea1").empty();
                $.ajax({  //页面首加载省下拉框数据
                    type: "post",  
                    url: "${pageContext.request.contextPath}/Main/Patient/loadcity.action",
            		async: true,
                    data:"cityparentcode="+cityparentcode,
                    success: function (data) {
                    	var datalist = data.list;
                        $('#hospadrarea1').append("<option value='0' selected='selected' >" + '---请选择区（县）---' + "</option>");  
                        for (var i = 0; i < datalist.length; i++) {
                            $('#hospadrarea1').append("<option value='" + datalist[i].citycode + "' >" + datalist[i].cityname + "</option>");  
                        }  
                    },  
                    error: function () {  
                        $.alert("加载县失败!!!");  
                    }  
                });
			}
		}
	</script>
	<script type="text/javascript">
	$(document).ready(function(){
    	$("#Ehospadr").click(function(){
    		$("#myMapModal").modal('show');
             setTimeout(function() {     //添加延时加载。解决问题
                 var map = new BMap.Map("map_main");
                 var myCity = new BMap.LocalCity();
                 var gc = new BMap.Geocoder();  //初始化，Geocoder类
                 myCity.get(function(res){
                     map.centerAndZoom(res.center,res.level);
                     map.enableScrollWheelZoom(); 		// 开启鼠标滚轮缩放，重要！
                     //向地图中添加缩放控件
                 	var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
                 	map.addControl(ctrl_nav);
                         //向地图中添加缩略图控件
                 	var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
                 	map.addControl(ctrl_ove);
                         //向地图中添加比例尺控件
                 	var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
                 	map.addControl(ctrl_sca);
                     /* var old_map = $('#map').val();      //如果已设置过
                     if(old_map.length > '5'){            //打开的时候显示已设置的
                         $("#map_txt").val(old_map);     
                         var oldMap = old_map.split(",");
                         var point = new BMap.Point(oldMap[0],oldMap[1]);    
                         var marker = new BMap.Marker(point);        // 创建标注    
                         map.clearOverlays();
                         map.addOverlay(marker);
                     } */
                     var hospadrlon = $("#Ehospadrlon").val();
                     var hospadrlat = $("#Ehospadrlat").val();
                     if(hospadrlon!="" && hospadrlat!=""){
                    	 var point = new BMap.Point(hospadrlon,hospadrlat);    
                         var marker = new BMap.Marker(point);        // 创建标注    
                         map.clearOverlays();
                         map.addOverlay(marker);
                     }
                     
                     map.addEventListener("click", function(e){
                         var lng_lat = e.point.lng+','+e.point.lat;
                         var point = new BMap.Point(e.point.lng,e.point.lat);    
                         var marker = new BMap.Marker(point);        // 创建标注  
                         gc.getLocation(point,function(rs){
                        	 var addComp = rs.addressComponents;
                        	 var province = addComp.province;//省  
                             var city = addComp.city;  //市
                             var area = addComp.district;//区
                             var street = addComp.street;//街
                             var streetnumber = addComp.streetNumber;
                             var Str = province+":"+city+":"+area+":"+street+":"+streetnumber;
                             $("#map_txt").val(lng_lat+"/"+Str);  //加入到设置框
                             $("#lng").val(e.point.lng);$("#lat").val(e.point.lat);
                             $("#province").val(province);$("#city").val(city);
                             $("#area").val(area);$("#other").val(street+streetnumber);
                         })
                         map.clearOverlays();
                         map.addOverlay(marker);
                     });
                 });
             },300);
         });
    });	
	function setMapValue(){
		var lng = $("#lng").val();
		var lat = $("#lat").val();
		var province = $("#province").val();
		var city = $("#city").val();
		var area = $("#area").val();
		var other = $("#other").val();
		$("#Ehospadrprovince").val(province);
    	$("#Ehospadrcity").val(city);
    	$("#Ehospadrarea").val(area);
    	$("#Ehospadrother").val(other);
    	$("#Ehospadrlon").val(lng);
    	$("#Ehospadrlat").val(lat);
    	$("#Ehospadr").val(province+":"+city+":"+area+":"+other);//+":"+lng+":"+lat
	}
	</script>
</body>
</html>